<?php
/**
 * User:于小涛
 * Date:2020/9/15
 * Time:14:07
 */
namespace app\api\controller\promotion;

use app\api\BaseController;
use app\api\model\promotion\PromotionRecord as PromotionRecordModel;
use app\api\model\promotion\SignRecord;
use app\api\model\promotion\VisitRecord;
use app\api\model\system\Channel;
use app\api\validate\promotion\PromotionRecord as PromotionRecordValidate;
use think\App;

class PromotionRecord extends BaseController{
    private $obj_promotion_record_model=null;
    private $obj_visit_record_model=null;
    private $obj_sign_record_model=null;
    private $obj_promotion_record_validate=null;
    private $obj_channel_model=null;
    private $arr_bind_channel_ids=[];
    private $arr_admin_list=[];
    private $arr_channel_list=[];
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->obj_promotion_record_model = new PromotionRecordModel();
        $this->obj_visit_record_model = new VisitRecord();
        $this->obj_sign_record_model = new SignRecord();
        $this->obj_promotion_record_validate = new PromotionRecordValidate();
        $this->obj_channel_model = new Channel();
        //获取推广专员绑定的渠道ids
        $arr_bind_channel_ids=$this->obj_channel_model
            ->alias("c")
            ->field('c.id')
            ->leftjoin('channel_bind_admin cba','cba.channel_id=c.id')
            ->where('cba.admin_id',$this->request->arr_admin_info['id'])
            ->select()
            ->toArray();
        foreach($arr_bind_channel_ids as $arr_item){
            $this->arr_bind_channel_ids[]=$arr_item['id'];
        }
        $this->arr_admin_list=$this->getAllAdmin();
        $this->arr_channel_list=$this->obj_channel_model->select()->toArray();
        $this->arr_channel_list=array_item_key_to_self_key($this->arr_channel_list,'id');
    }

    public function addPromotionRecord(){
        //检查参数
        if(!$this->obj_promotion_record_validate->scene(__FUNCTION__)->check($this->request->param()))
        {
            trace("参数验证失败,".$this->obj_promotion_record_validate->getError(),'error');
            return output_data(array(),'paramserror',$this->obj_promotion_record_validate->getError());
        }
        $arr_channel_ids=explode(',',$this->request->param('channel_ids'));
        $arr_nums=explode(',',$this->request->param('nums'));
        $arr_chuangye_admin_ids=explode(',',$this->request->param('chuangye_admin_ids'));
        if((count($arr_channel_ids)!=count($arr_nums))||(count($arr_nums)!=count($arr_chuangye_admin_ids))||(count($arr_channel_ids)!=count($arr_chuangye_admin_ids))){
            $str_log="参数验证失败,三组数据数量不一致";
            trace($str_log,'error');
            return output_data(array(),'paramserror',$str_log);
        }
        //判断是否是推广员
        $arr_role_ids=$this->getRoleIds($this->request->arr_admin_info['id']);
        //如果是推广员和创业导师则只能够查看自己的
        if(!in_array(config('project.role_id.tuiguangzhuanyuan.id'),$arr_role_ids)){
            $str_log="当前账号不是推广员";
            trace($str_log,'error');
            return output_data(array(),'promotionisnottuiguangyuan');
        }
        //判断提交的数据是否合法
        $arr_diff=array_diff($arr_channel_ids,$this->arr_bind_channel_ids);
        if($arr_diff){
            $str_log="提交的数据中有多余的渠道,请退出重新添加";
            trace($str_log,'error');
            return output_data(array(),'paramserror',$str_log);
        }
        $this->obj_promotion_record_model->startTrans();
        //检查本次提交的所有创业顾问是否有录入当天的数据，如果有需要验证合理性，如果没有则不处理
        foreach($arr_chuangye_admin_ids as $int_key=>$int_chuangye_admin_id){
            //判断渠道是否重复
            $arr_check_date=$this->obj_promotion_record_model
                ->where('date',$this->request->param('date'))
                ->where('channel_id',$arr_channel_ids[$int_key])
                ->where('tuiguang_admin_id',$this->request->arr_admin_info['id'])
                ->where('tuiguang_is_add',2)
                ->select()
                ->toArray();
            if(!empty($arr_check_date)){
                $str_log="渠道【{$this->arr_channel_list[$arr_channel_ids[$int_key]]['name']}】重复";
                trace($str_log,'error');
                return output_data(array(),'promotiondaterepeat',$str_log);
            }
            $arr_check_chuangye_admin=$this->obj_promotion_record_model
                ->where('date',$this->request->param('date'))
                ->where('chuangye_admin_id',$int_chuangye_admin_id)
                ->where('chuangye_is_add',2)
                ->select()
                ->toArray();
            //如果已经录入
            if(!empty($arr_check_chuangye_admin)){
                //判断创业顾问录入的数据中，是否有当前推广专员
                $arr_check_chuangye_has_current_tuiguang_admin=$this->obj_promotion_record_model
                    ->where('date',$this->request->param('date'))
                    ->where('channel_id',$arr_channel_ids[$int_key])
                    ->where('chuangye_admin_id',$int_chuangye_admin_id)
                    ->where('tuiguang_admin_id',$this->request->arr_admin_info['id'])
                    ->select()
                    ->toArray();
                if(empty($arr_check_chuangye_has_current_tuiguang_admin)){
                    $str_log="创业顾问已经录入该天数据，但是没有推广员【{$this->arr_admin_list[$this->request->arr_admin_info['id']]['name']}】的【{$this->arr_channel_list[$arr_channel_ids[$int_key]]['name']}】渠道数据";
                    trace($str_log,'error');
                    $this->obj_promotion_record_model->rollback();
                    return output_data([],'systemerror',$str_log);
                }
                //判断推总量是否小于有效量
                if($arr_nums[$int_key]<$arr_check_chuangye_has_current_tuiguang_admin[0]['valid_num']){
                    $str_log="创业顾问已经录入该天数据，你录入的渠道【{$this->arr_channel_list[$arr_channel_ids[$int_key]]['name']}】的总量【{$arr_nums[$int_key]}】小于有效量【{$arr_check_chuangye_has_current_tuiguang_admin[0]['valid_num']}】";
                    trace($str_log,'error');
                    $this->obj_promotion_record_model->rollback();
                    return output_data([],'systemerror',$str_log);
                }
                //执行修改操作
                $arr_edit_data=[
                    'all_num'=>$arr_nums[$int_key],
                    'tuiguang_is_add'=>2,
                ];
                $int_edit_num=$this->obj_promotion_record_model->edit($arr_check_chuangye_has_current_tuiguang_admin[0]['id'],$arr_edit_data);
                if($int_edit_num){
                    trace("修改成功，数据：".var_export($arr_edit_data,true).",返回：".$int_edit_num,'info');
                }else{
                    trace("添加失败，数据：".var_export($arr_edit_data,true).",返回：".$int_edit_num,'error');
                    $this->obj_promotion_record_model->rollback();
                    return output_data([],'systemerror');
                }
            }else{//如果没有录入，则直接添加
                $arr_add_data=[
                    'date'=>$this->request->param('date'),
                    'channel_id'=>$arr_channel_ids[$int_key],
                    'all_num'=>$arr_nums[$int_key],
                    'tuiguang_admin_id'=>$this->request->arr_admin_info['id'],
                    'tuiguang_is_add'=>2,
                    'chuangye_admin_id'=>$arr_chuangye_admin_ids[$int_key]
                ];
                $int_add_num=$this->obj_promotion_record_model->add($arr_add_data);
                if($int_add_num){
                    trace("添加成功，数据：".var_export($arr_add_data,true).",返回：".$int_add_num,'info');
                }else{
                    trace("添加失败，数据：".var_export($arr_add_data,true).",返回：".$int_add_num,'error');
                    $this->obj_promotion_record_model->rollback();
                    return output_data([],'systemerror');
                }
            }
        }
        $this->obj_promotion_record_model->commit();
        return output_data([]);
    }

    public function addPromotionValidRecord(){
        //检查参数
        if(!$this->obj_promotion_record_validate->scene(__FUNCTION__)->check($this->request->param()))
        {
            trace("参数验证失败,".$this->obj_promotion_record_validate->getError(),'error');
            return output_data(array(),'paramserror',$this->obj_promotion_record_validate->getError());
        }
        //判断是否是推广员
        $arr_role_ids=$this->getRoleIds($this->request->arr_admin_info['id']);
        //如果是推广员和创业导师则只能够查看自己的
        if(!in_array(config('project.role_id.chuangyeguwen.id'),$arr_role_ids)){
            $str_log="当前账号不是创业顾问";
            trace($str_log,'error');
            return output_data(array(),'systemerror',$str_log);
        }
        $this->obj_promotion_record_model->startTrans();
        if(!empty($this->request->param('promotion_channel_ids'))){
            $arr_re=$this->_addPromotionValidRecord();
            if($arr_re['ret']!=0){
                $this->obj_promotion_record_model->rollback();
                return output_data(array(),'systemerror',$arr_re['reason']);
            }
        }
        if(!empty($this->request->param('visit_channel_ids'))){
            $arr_re=$this->_addVisitRecord();
            if($arr_re['ret']!=0){
                $this->obj_promotion_record_model->rollback();
                return output_data(array(),'systemerror',$arr_re['reason']);
            }
        }
        if(!empty($this->request->param('sign_channel_ids'))){
            $arr_re=$this->_addSignRecord();
            if($arr_re['ret']!=0){
                $this->obj_promotion_record_model->rollback();
                return output_data(array(),'systemerror',$arr_re['reason']);
            }
        }

        $this->obj_promotion_record_model->commit();
        return output_data([]);
    }

    /**
     * 添加有效资源
     * User:于小涛
     * Date:2020/10/8
     * Time:19:19
     */
    private function _addPromotionValidRecord(){
        $arr_channel_ids=explode(',',$this->request->param('promotion_channel_ids'));
        $arr_nums=explode(',',$this->request->param('promotion_nums'));
        $arr_tuiguang_admin_ids=explode(',',$this->request->param('promotion_tuiguang_admin_ids'));
        if((count($arr_channel_ids)!=count($arr_nums))||(count($arr_nums)!=count($arr_tuiguang_admin_ids))||(count($arr_channel_ids)!=count($arr_tuiguang_admin_ids))){
            $str_log="参数验证失败,三组数据数量不一致";
            trace($str_log,'error');
            return ['ret'=>1,'reason'=>$str_log];
        }
        //检查本次提交的所有推广员是否有录入当天的数据，如果有需要验证合理性，如果没有则不处理
        foreach($arr_tuiguang_admin_ids as $int_key=>$int_tuiguang_admin_id){
            //判断渠道是否重复
            $arr_check_date=$this->obj_promotion_record_model
                ->where('date',$this->request->param('date'))
                ->where('channel_id',$arr_channel_ids[$int_key])
                ->where('chuangye_admin_id',$this->request->arr_admin_info['id'])
                ->where('chuangye_is_add',2)
                ->select()
                ->toArray();
            if(!empty($arr_check_date)){
                $str_log="渠道【{$this->arr_channel_list[$arr_channel_ids[$int_key]]['name']}】重复";
                trace($str_log,'error');
                return ['ret'=>1,'reason'=>$str_log];
            }
            $arr_check_tuiguang_admin=$this->obj_promotion_record_model
                ->where('date',$this->request->param('date'))
                ->where('tuiguang_admin_id',$int_tuiguang_admin_id)
                ->where('tuiguang_is_add',2)
                ->select()
                ->toArray();
            //如果已经录入
            if(!empty($arr_check_tuiguang_admin)){
                //判断推广员录入的数据中，是否有当前创业顾问
                $arr_check_tuiguang_has_current_chuangye_admin=$this->obj_promotion_record_model
                    ->where('date',$this->request->param('date'))
                    ->where('channel_id',$arr_channel_ids[$int_key])
                    ->where('tuiguang_admin_id',$int_tuiguang_admin_id)
                    ->where('chuangye_admin_id',$this->request->arr_admin_info['id'])
                    ->select()
                    ->toArray();
                if(empty($arr_check_tuiguang_has_current_chuangye_admin)){
                    $str_log="推广员已经录入该天数据，但是没有创业顾问【{$this->arr_admin_list[$this->request->arr_admin_info['id']]['name']}】的【{$this->arr_channel_list[$arr_channel_ids[$int_key]]['name']}】渠道数据";
                    trace($str_log,'error');
                    return ['ret'=>1,'reason'=>$str_log];
                }
                //判断推总量是否小于有效量
                if($arr_nums[$int_key]>$arr_check_tuiguang_has_current_chuangye_admin[0]['all_num']){
                    $str_log="推广员已经录入该天数据，你录入的渠道【{$this->arr_channel_list[$arr_channel_ids[$int_key]]['name']}】的有效量【{$arr_nums[$int_key]}】大于总量【{$arr_check_tuiguang_has_current_chuangye_admin[0]['all_num']}】";
                    trace($str_log,'error');
                    return ['ret'=>1,'reason'=>$str_log];
                }
                //执行修改操作
                $arr_edit_data=[
                    'valid_num'=>$arr_nums[$int_key],
                    'chuangye_is_add'=>2,
                ];
                $int_edit_num=$this->obj_promotion_record_model->edit($arr_check_tuiguang_has_current_chuangye_admin[0]['id'],$arr_edit_data);
                if($int_edit_num){
                    trace("修改成功，数据：".var_export($arr_edit_data,true).",返回：".$int_edit_num,'info');
                }else{
                    $str_log="添加失败，数据：".var_export($arr_edit_data,true).",返回：".$int_edit_num;
                    trace($str_log,'error');
                    return ['ret'=>1,'reason'=>$str_log];
                }
            }else{//如果没有录入，则直接添加
                $arr_add_data=[
                    'date'=>$this->request->param('date'),
                    'channel_id'=>$arr_channel_ids[$int_key],
                    'valid_num'=>$arr_nums[$int_key],
                    'chuangye_admin_id'=>$this->request->arr_admin_info['id'],
                    'chuangye_is_add'=>2,
                    'tuiguang_admin_id'=>$arr_tuiguang_admin_ids[$int_key]
                ];
                $int_add_num=$this->obj_promotion_record_model->add($arr_add_data);
                if($int_add_num){
                    trace("添加成功，数据：".var_export($arr_add_data,true).",返回：".$int_add_num,'info');
                }else{
                    $str_log="添加失败，数据：".var_export($arr_add_data,true).",返回：".$int_add_num;
                    trace($str_log,'error');
                    return ['ret'=>1,'reason'=>$str_log];
                }
            }
        }
        return ['ret'=>0,'reason'=>'success'];
    }

    /**
     * 添加到访量
     * User:于小涛
     * Date:2020/10/8
     * Time:19:19
     */
    private function _addVisitRecord(){
        $arr_channel_ids=explode(',',$this->request->param('visit_channel_ids'));
        $arr_nums=explode(',',$this->request->param('visit_nums'));
        $arr_tuiguang_admin_ids=explode(',',$this->request->param('visit_tuiguang_admin_ids'));
        if((count($arr_channel_ids)!=count($arr_nums))||(count($arr_nums)!=count($arr_tuiguang_admin_ids))||(count($arr_channel_ids)!=count($arr_tuiguang_admin_ids))){
            $str_log="参数验证失败,三组数据数量不一致";
            trace($str_log,'error');
            return ['ret'=>1,'reason'=>$str_log];
        }
        foreach($arr_tuiguang_admin_ids as $int_key=>$int_tuiguang_admin_id){
            //判断日期是否重复
            $arr_check_date=$this->obj_visit_record_model
                ->where('date',$this->request->param('date'))
                ->where('channel_id',$arr_channel_ids[$int_key])
                ->where('tuiguang_admin_id',$arr_tuiguang_admin_ids[$int_key])
                ->where('chuangye_admin_id',$this->request->arr_admin_info['id'])
                ->select()
                ->toArray();
            if(!empty($arr_check_date)){
                $str_log="渠道【{$this->arr_channel_list[$arr_channel_ids[$int_key]]['name']}】推广员【{$this->arr_admin_list[$arr_tuiguang_admin_ids[$int_key]]['name']}】重复";
                trace($str_log,'error');
                return ['ret'=>1,'reason'=>$str_log];
            }
            $arr_add_data=[
                'date'=>$this->request->param('date'),
                'channel_id'=>$arr_channel_ids[$int_key],
                'num'=>$arr_nums[$int_key],
                'chuangye_admin_id'=>$this->request->arr_admin_info['id'],
                'tuiguang_admin_id'=>$arr_tuiguang_admin_ids[$int_key]
            ];
            $int_add_num=$this->obj_visit_record_model->add($arr_add_data);
            if($int_add_num){
                trace("添加成功，数据：".var_export($arr_add_data,true).",返回：".$int_add_num,'info');
            }else{
                $str_log="添加失败，数据：".var_export($arr_add_data,true).",返回：".$int_add_num;
                trace($str_log,'error');
                return ['ret'=>1,'reason'=>$str_log];
            }
        }
        return ['ret'=>0,'reason'=>'success'];
    }

    /**
     * 添加签约量
     * User:于小涛
     * Date:2020/10/8
     * Time:19:19
     */
    private function _addSignRecord(){
        $arr_channel_ids=explode(',',$this->request->param('sign_channel_ids'));
        $arr_nums=explode(',',$this->request->param('sign_nums'));
        $arr_tuiguang_admin_ids=explode(',',$this->request->param('sign_tuiguang_admin_ids'));
        if((count($arr_channel_ids)!=count($arr_nums))||(count($arr_nums)!=count($arr_tuiguang_admin_ids))||(count($arr_channel_ids)!=count($arr_tuiguang_admin_ids))){
            $str_log="参数验证失败,三组数据数量不一致";
            trace($str_log,'error');
            return ['ret'=>1,'reason'=>$str_log];
        }
        foreach($arr_tuiguang_admin_ids as $int_key=>$int_tuiguang_admin_id){
            //判断日期是否重复
            $arr_check_date=$this->obj_visit_record_model
                ->where('date',$this->request->param('date'))
                ->where('channel_id',$arr_channel_ids[$int_key])
                ->where('tuiguang_admin_id',$arr_tuiguang_admin_ids[$int_key])
                ->where('chuangye_admin_id',$this->request->arr_admin_info['id'])
                ->select()
                ->toArray();
            if(!empty($arr_check_date)){
                $str_log="渠道【{$this->arr_channel_list[$arr_channel_ids[$int_key]]['name']}】推广员【{$this->arr_admin_list[$arr_tuiguang_admin_ids[$int_key]]['name']}】重复";
                trace($str_log,'error');
                return ['ret'=>1,'reason'=>$str_log];
            }
            $arr_add_data=[
                'date'=>$this->request->param('date'),
                'channel_id'=>$arr_channel_ids[$int_key],
                'num'=>$arr_nums[$int_key],
                'chuangye_admin_id'=>$this->request->arr_admin_info['id'],
                'tuiguang_admin_id'=>$arr_tuiguang_admin_ids[$int_key]
            ];
            $int_add_num=$this->obj_sign_record_model->add($arr_add_data);
            if($int_add_num){
                trace("添加成功，数据：".var_export($arr_add_data,true).",返回：".$int_add_num,'info');
            }else{
                $str_log="添加失败，数据：".var_export($arr_add_data,true).",返回：".$int_add_num;
                trace($str_log,'error');
                return ['ret'=>1,'reason'=>$str_log];
            }
        }
        return ['ret'=>0,'reason'=>'success'];
    }

    public function getList(){
        $arr_list_re=[];
        switch ($this->request->param('type',1)){
            case 1:
                $arr_list_re=$this->_getPromotionList();
                break;
            case 2:
                $arr_list_re=$this->_getVisitList();
                break;
            case 3:
                $arr_list_re=$this->_getSignList();
                break;
        }
        return output_data($arr_list_re);
    }

    private function _getPromotionList(){
        $arr_where=[];
        if(!empty($this->request->param('date'))){
            $arr_where[]=['pr.date','=',$this->request->param('date')];
        }
        if(!empty($this->request->param('channel_id'))){
            $arr_where[]=['pr.channel_id','=',$this->request->param('channel_id')];
        }
        if(!empty($this->request->param('tuiguang_admin_id'))){
            $arr_where[]=['pr.tuiguang_admin_id','=',$this->request->param('tuiguang_admin_id')];
        }
        if(!empty($this->request->param('chuangye_admin_id'))){
            $arr_where[]=['pr.chuangye_admin_id','=',$this->request->param('chuangye_admin_id')];
        }
        //判断角色
        $arr_role_ids=$this->getRoleIds($this->request->arr_admin_info['id']);
        //如果是推广员和创业导师则只能够查看自己的
        if(in_array(config('project.role_id.tuiguangzhuanyuan.id'),$arr_role_ids)){
            $arr_where[]=['pr.tuiguang_admin_id','=',$this->request->arr_admin_info['id']];
        }
        if(in_array(config('project.role_id.chuangyeguwen.id'),$arr_role_ids)){
            $arr_where[]=['pr.chuangye_admin_id','=',$this->request->arr_admin_info['id']];
        }
        $arr_list=$this->obj_promotion_record_model
            ->alias('pr')
            ->field('pr.*,c.name as channel_name')
            ->leftjoin('channel c ','c.id=pr.channel_id')
            ->where($arr_where)
            ->order('pr.id','desc')
            ->paginate(['list_rows'=>$this->request->param('page_size',20),'page'=>$this->request->param('page_index',1)])
            ->toArray();
        $arr_list_re=[
            'list'=>[],
            'total'=>$arr_list['total']
        ];
        foreach($arr_list['data'] as $arr_item){
            $arr_list_re_item=[
                'date'=>$arr_item['date'],
                'channel_name'=>$arr_item['channel_name'],
                'all_num'=>$arr_item['all_num'],
                'valid_num'=>$arr_item['valid_num'],
                'create_time'=>$arr_item['create_time'],
            ];
            $arr_list_re_item['tuiguang_admin_name']=$this->arr_admin_list[$arr_item['tuiguang_admin_id']]['name'];
            $arr_list_re_item['chuangye_admin_name']=empty($arr_item['chuangye_admin_id'])?'':$this->arr_admin_list[$arr_item['chuangye_admin_id']]['name'];
            $arr_list_re_item['valid_num']=empty($arr_item['chuangye_admin_id'])?'':$arr_item['valid_num'];
            //计算有效率
            if(empty($arr_item['chuangye_admin_id'])){
                $arr_list_re_item['valid_per']='';
            }else{
                if(empty($arr_item['all_num'])){
                    $arr_list_re_item['valid_per']=0;
                }else{
                    if(empty($arr_item['valid_num'])){
                        $arr_list_re_item['valid_per']='0.0%';
                    }else{
                        $arr_list_re_item['valid_per']=(number_format($arr_item['valid_num']/$arr_item['all_num'],3,'.','')*100).'%';
                    }
                }
            }
            $arr_list_re['list'][]=$arr_list_re_item;
        }
        return $arr_list_re;
    }

    private function _getVisitList(){
        $arr_where=[];
        if(!empty($this->request->param('date'))){
            $arr_where[]=['vr.date','=',$this->request->param('date')];
        }
        if(!empty($this->request->param('channel_id'))){
            $arr_where[]=['vr.channel_id','=',$this->request->param('channel_id')];
        }
        if(!empty($this->request->param('tuiguang_admin_id'))){
            $arr_where[]=['vr.tuiguang_admin_id','=',$this->request->param('tuiguang_admin_id')];
        }
        if(!empty($this->request->param('chuangye_admin_id'))){
            $arr_where[]=['vr.chuangye_admin_id','=',$this->request->param('chuangye_admin_id')];
        }
        //判断角色
        $arr_role_ids=$this->getRoleIds($this->request->arr_admin_info['id']);
        //如果是创业顾问则只能够查看自己的
        if(in_array(config('project.role_id.chuangyeguwen.id'),$arr_role_ids)){
            $arr_where[]=['vr.chuangye_admin_id','=',$this->request->arr_admin_info['id']];
        }
        $arr_list=$this->obj_visit_record_model
            ->alias('vr')
            ->field('vr.*,c.name as channel_name')
            ->leftjoin('channel c ','c.id=vr.channel_id')
            ->where($arr_where)
            ->order('vr.id','desc')
            ->paginate(['list_rows'=>$this->request->param('page_size',20),'page'=>$this->request->param('page_index',1)])
            ->toArray();
        $arr_list_re=[
            'list'=>[],
            'total'=>$arr_list['total']
        ];
        foreach($arr_list['data'] as $arr_item){
            $arr_list_re_item=[
                'date'=>$arr_item['date'],
                'channel_name'=>$arr_item['channel_name'],
                'num'=>$arr_item['num'],
                'create_time'=>$arr_item['create_time'],
            ];
            $arr_list_re_item['tuiguang_admin_name']=$this->arr_admin_list[$arr_item['tuiguang_admin_id']]['name'];
            $arr_list_re_item['chuangye_admin_name']=empty($arr_item['chuangye_admin_id'])?'':$this->arr_admin_list[$arr_item['chuangye_admin_id']]['name'];
            $arr_list_re['list'][]=$arr_list_re_item;
        }
        return $arr_list_re;
    }

    private function _getSignList(){
        $arr_where=[];
        if(!empty($this->request->param('date'))){
            $arr_where[]=['sr.date','=',$this->request->param('date')];
        }
        if(!empty($this->request->param('channel_id'))){
            $arr_where[]=['sr.channel_id','=',$this->request->param('channel_id')];
        }
        if(!empty($this->request->param('tuiguang_admin_id'))){
            $arr_where[]=['sr.tuiguang_admin_id','=',$this->request->param('tuiguang_admin_id')];
        }
        if(!empty($this->request->param('chuangye_admin_id'))){
            $arr_where[]=['sr.chuangye_admin_id','=',$this->request->param('chuangye_admin_id')];
        }
        //判断角色
        $arr_role_ids=$this->getRoleIds($this->request->arr_admin_info['id']);
        //如果是创业顾问则只能够查看自己的
        if(in_array(config('project.role_id.chuangyeguwen.id'),$arr_role_ids)){
            $arr_where[]=['sr.chuangye_admin_id','=',$this->request->arr_admin_info['id']];
        }
        $arr_list=$this->obj_sign_record_model
            ->alias('sr')
            ->field('sr.*,c.name as channel_name')
            ->leftjoin('channel c ','c.id=sr.channel_id')
            ->where($arr_where)
            ->order('sr.id','desc')
            ->paginate(['list_rows'=>$this->request->param('page_size',20),'page'=>$this->request->param('page_index',1)])
            ->toArray();
        $arr_list_re=[
            'list'=>[],
            'total'=>$arr_list['total']
        ];
        foreach($arr_list['data'] as $arr_item){
            $arr_list_re_item=[
                'date'=>$arr_item['date'],
                'channel_name'=>$arr_item['channel_name'],
                'num'=>$arr_item['num'],
                'create_time'=>$arr_item['create_time'],
            ];
            $arr_list_re_item['tuiguang_admin_name']=$this->arr_admin_list[$arr_item['tuiguang_admin_id']]['name'];
            $arr_list_re_item['chuangye_admin_name']=empty($arr_item['chuangye_admin_id'])?'':$this->arr_admin_list[$arr_item['chuangye_admin_id']]['name'];
            $arr_list_re['list'][]=$arr_list_re_item;
        }
        return $arr_list_re;
    }

}